package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.SecurityList;
import com.example.prison.entity.vo.SecurityListVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【security_list】的数据库操作Mapper
* @createDate 2023-04-11 17:10:33
* @Entity com.example.military.entity.SecurityList
*/
@Mapper
public interface SecurityListMapper extends BaseMapper<SecurityList> {

    @Select("select * from security_list order by record_id desc")
    List<SecurityList> getSecurityList();

//    @Select("select * from security_list s, security_device_info d where s.sn=d.device_number order by record_id desc")
    @Select("<script>select * from security_list s, security_device_info d " +
            " <where> s.sn=d.device_number" +
            " <if test=\"sn != null and sn != ''\">and sn like concat('%',#{sn},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and time &lt;= #{endTime} </if> " +
            " </where> " +
            "order by record_id desc</script>")
    List<SecurityListVO> getInfoList(@Param("sn")String sn, @Param("beginTime")String beginTime, @Param("endTime")String endTime);

    @Insert("insert into security_list(pin,time,sn)" +
            "values (#{pin},#{time},#{sn})")
    void addSecurityRecord(SecurityList securityList);

    @Delete("<script>delete from security_list where record_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteSecurityList(@Param("ids") Integer[] ids);

    @Select("select * from security_list s, security_device_info d where s.time between #{beginTime} and #{endTime} and s.sn=d.device_number order by record_id desc")
    List<SecurityListVO> getListByTime(String beginTime, String endTime);

    @Select("select * from security_list where record_id=#{id} ")
    SecurityList getById(@Param("id") Integer id);

    @Select("select * from security_list s, security_device_info d where s.sn=d.device_number and s.sn=#{sn} order by record_id desc")
    List<SecurityListVO> getListBySN(@Param("sn") String sn);
}




